/*
 * $Id: PolisData.java 27 2007-04-13 01:02:48Z aaron.day $
 */
package org.crazydays.core.data;


import java.io.Serializable;
import java.sql.Date;

import javax.persistence.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Base class for polis data.
 */
@MappedSuperclass
public class PolisData
	implements Comparable, Serializable
{
	/** serial version uid */
	public final static long serialVersionUID = "$Id: PolisData.java 27 2007-04-13 01:02:48Z aaron.day $".hashCode();

	/** Log */
	@Transient
	protected Log LOG = LogFactory.getLog(getClass());

	/** id */
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "POLIS_IDS")
	@Column(unique = true, nullable = false)
	protected long id;

	/** name */
	@Basic
	@Column(unique = true)
	protected String name;

	/** description */
	@Basic
	@Column(nullable = true)
	protected String description;

	/** summary */
	@Basic
	@Column(nullable = true)
	protected String summary;

	/** updated */
	@Basic
	@Column(nullable = true)
	protected Date updated;

	/** created */
	@Basic
	@Column(nullable = true)
	protected Date created;

	/** deleted */
	@Basic
	@Column(nullable = true)
	protected Date deleted;

	/**
	 * Set id.
	 * 
	 * @param id Id
	 */
	public void setId(long id)
	{
		this.id = id;
	}

	/**
	 * Get id.
	 * 
	 * @return Id
	 */
	public long getId()
	{
		return id;
	}

	/**
	 * Set name.
	 * 
	 * @param name Name
	 */
	public void setName(String name)
	{
		this.name = name;
	}

	/**
	 * Get name.
	 * 
	 * @return Name
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * Set description.
	 * 
	 * @param description Description
	 */
	public void setDescription(String description)
	{
		this.description = description;
	}

	/**
	 * Get description.
	 * 
	 * @return Description
	 */
	public String getDescription()
	{
		return description;
	}

	/**
	 * Set summary.
	 * 
	 * @param summary Summary
	 */
	public void setSummary(String summary)
	{
		this.summary = summary;
	}

	/**
	 * Get summary.
	 * 
	 * @return Summary
	 */
	public String getSummary()
	{
		return summary;
	}

	/**
	 * Set updated time.
	 * 
	 * @param updated Updated
	 */
	public void setUpdated(Date updated)
	{
		this.updated = updated;
	}

	/**
	 * Get updated date.
	 * 
	 * @return Updated
	 */
	public Date getUpdated()
	{
		return updated;
	}

	/**
	 * Set created.
	 * 
	 * @param created Created
	 */
	public void setCreated(Date created)
	{
		this.created = created;
	}

	/**
	 * Get created.
	 * 
	 * @return Created
	 */
	public Date getCreated()
	{
		return created;
	}

	/**
	 * Set deleted.
	 * 
	 * @param deleted Deleted
	 */
	public void setDeleted(Date deleted)
	{
		this.deleted = deleted;
	}

	/**
	 * Get deleted.
	 * 
	 * @return Deleted
	 */
	public Date getDeleted()
	{
		return deleted;
	}

	public int compareTo(Object o)
	{
		if (o == null) {
			throw new IllegalArgumentException("o == null");
		} else if (getClass().isInstance(o)) {
			PolisData d = (PolisData) o;

			if (getName() == null) {
				return -1;
			} else {
				return getName().compareTo(d.getName());
			}
		} else {
			throw new ClassCastException(getClass().getName()
					+ " is not comparable "
					+ o.getClass().getName());
		}
	}

	/**
	 * Equal
	 * 
	 * @param o Object
	 * @return Equal
	 */
	public boolean equals(Object o)
	{
		if (o == null) {
			return false;
		} else if (getClass().isInstance(o)) {
			PolisData d = (PolisData) o;

			return getId() == d.getId();
		} else {
			return false;
		}
	}

	/**
	 * Hash code
	 * 
	 * @return Hash code
	 */
	public int hashCode()
	{
		int hashCode = 0;

		String name = getName();
		if (name != null) {
			hashCode = name.hashCode();
		}

		return hashCode;
	}

	/**
	 * To string.
	 * 
	 * @return String
	 */
	public String toString()
	{
		StringBuffer buffer = new StringBuffer();

		buffer.append(getClass().getName().replaceAll(".*?\\.", ""));
		buffer.append(" id: ");
		buffer.append(getId());
		buffer.append(" name: ");
		buffer.append(getName());
		buffer.append(" description: ");
		buffer.append(getDescription());
		buffer.append(" summary: ");
		buffer.append(getSummary());

		return buffer.toString();
	}
}
